var checkStr = "0123456789X";
var updoc = window.dialogArguments.document;

function getParentTR(dom) {
	if (dom) {
		if (dom.tagName.toLowerCase() == 'tr') {
			return dom;
		} else {
			return getParentTR(dom.parentNode);
		}
	} else {
		return null;
	}
}

function query() {

	var number = document.getElementById("number").value.replace(/ /g, '');
	document.getElementById("number").value = number;
	if (number.length != 15 && number.length != 18) {
		alert("身份证号为15位或18位字符串，请重新检查。谢谢！");
		return false;
	}
	for (var i = 0; i < number.length; i++) {
		var temp = number.charAt(i);
		if (checkStr.indexOf(temp) == -1) {
			alert("单据编号的半角阿拉伯数字或X，请重新检查。谢谢！");
			return false;
		}
	}

	for (var i = 0; i < updoc.getElementsByName("my:人员身份证号").length; i++) {
		if (updoc.getElementsByName("my:人员身份证号")[i].value == number) {
			alert("该人员身份证号已经已添加");
			return false;
		}
	}

	window.parent.document.getElementById("lodingDiv").style.height = window.parent.document.body.clientHeight
			- 3 + "px";
	window.parent.document.getElementById("lodingDiv").style.display = '';

	var xmlhttp = null;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera,
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				text = xmlhttp.responseText;

				var result = eval('(' + text + ')');
				if (result.success == true) {
					
					var numberInputs = updoc.getElementsByName("my:人员身份证号");
					var rowSize = numberInputs.length;
					var rowIndex = 0;
					if (numberInputs[0].value != "") {
						var trDom = getParentTR(numberInputs[rowSize - 1]);
						var trNodes = trDom.parentNode.childNodes;
						for (var i = 0; i < trNodes.length; i++) {
							trNodes[i].id = "";
						}
						trDom.id = "oper";
						window.dialogArguments.addEmpty();
						rowIndex = rowSize;
						trDom.id = "";
					}
					for (var key in result.data) {
						updoc.getElementsByName("my:" + key)[rowIndex].value = result.data[key];
					}
					window.close();
				} else {
					alert(result.data);
				}
			} else {
				alert("连接服务器异常");
			}

			window.parent.document.getElementById("lodingDiv").style.display = 'none';
		}
	};
	xmlhttp.open("get",
			"../../../../oa2hrController.do?method=queryRequirementPersonInfo&number="
					+ document.getElementById("number").value, true);
	xmlhttp.send();

	return false;
}